<!--
 * @Author: licongwei
 * @Date: 2022-03-07 17:23:15
 * @FileDescription: 生产资料
-->
<template>
  <div class="P2">
    <div class="left box">
      <left-top
        @change="handPieChange"
        class="left-top box-top"
        ref="refLeftTop"
      ></left-top>
      <left-lower
        @change="handListChange"
        :classId="classId"
        class="left-lower box-lower"
        ref="refLeftLower"
      ></left-lower>
    </div>
    <div class="center box">
      <div class="center-top box-top">
        <center-top
          :goodsId="goodsId"
          ref="refCenterTop"
          @enlarge="onCenterTopEnlarge"
        >
          <template #titleRight>
            <el-icon
              class="item-icon centerTop"
              :class="{ active: isTransition }"
              @click="handIconClick('centerTopModal')"
            >
              <ZoomIn />
            </el-icon>
          </template>
        </center-top>
      </div>
      <center-lower
        :goodsId="goodsId"
        :classId="classId"
        :goodsName="goodsName"
        class="center-lower box-lower"
        ref="refCenterLower"
      ></center-lower>
    </div>
    <div class="right box">
      <right-top
        :goodsId="goodsId"
        class="right-top box-top"
        ref="refRightTop"
        :isTransition="isTransition"
        @enlarge="handIconClick('rightTopModal')"
      ></right-top>
      <right-lower
        :goodsId="goodsId"
        class="right-lower box-lower"
        ref="refRightLower"
        :isTransition="isTransition"
        @enlarge="handIconClick('rightLowerModal')"
      ></right-lower>
    </div>
    <div class="enlarge">
      <enlarge-vue
        class="enlarge-nav"
        v-show="isTransition"
        :style="
          isTransition
            ? { 'z-index': 999, opacity: 1, top: '0px' }
            : { 'z-index': 0, opacity: 0, top: '100vh' }
        "
        @close="handIconClick('')"
      >
        <transition
          name="fade"
          :enter-from-class="transitionName"
          :leave-to-class="transitionName"
        >
          <component
            style="background-color: #001949"
            :is="iconText"
            :goodsId="goodsId"
            :goodsName="goodsName"
            ref="refEnlarge"
          />
        </transition>
      </enlarge-vue>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, computed, watch, shallowRef } from 'vue'
import { useStore } from 'vuex'
import leftTop from './cpns/leftTop.vue'
import leftLower from './cpns/leftLower.vue'
import centerTop from './cpns/centerTop.vue'
import centerLower from './cpns/centerLower.vue'
import rightTop from './cpns/rightTop.vue'
import rightLower from './cpns/rightLower.vue'
import { ZoomIn } from '@element-plus/icons-vue'
import enlargeVue from '../P2/cpns/enlarge.vue'
import centerTopModal from './cpns/modal/centerTop.vue'
import rightTopModal from './cpns/modal/rightTop.vue'
import rightLowerModal from './cpns/modal/rightLower.vue'

export default defineComponent({
  name: 'M6',
  components: {
    leftTop,
    leftLower,
    centerTop,
    centerLower,
    rightTop,
    rightLower,
    enlargeVue,
    ZoomIn,
    centerTopModal,
    rightTopModal,
    rightLowerModal
  },
  setup() {
    const classId = ref('')
    const goodsId = ref('')
    const goodsName = ref('')
    const refLeftTop = ref()
    const refLeftLower = ref()
    const refCenterTop = ref()
    const refCenterLower = ref()
    const refRightTop = ref()
    const refRightLower = ref()
    const refEnlarge = ref()
    const store = useStore()
    const handPieChange = (id: string) => {
      classId.value = id
    }
    const handListChange = (id: string, name: string) => {
      goodsId.value = id
      goodsName.value = name
    }
    const watchedState = computed(() => Object.values(store.state.globalDate))
    watch(watchedState, () => {
      refLeftTop.value?.refreshData()
      refLeftLower.value?.refreshData()
      refCenterTop.value?.refreshData()
      refCenterLower.value?.refreshData()
      refRightTop.value?.refreshData()
      refRightLower.value?.refreshData()
      refEnlarge.value?.refreshData()
    })

    const isTransition = ref(false)
    const transitionName = ref('')
    const iconText = ref('')
    const handIconClick = (text: string) => {
      if (text) {
        iconText.value = text
        isTransition.value = true
        transitionName.value = 'fade'
      } else {
        isTransition.value = false
        transitionName.value = ''
        setTimeout(() => {
          iconText.value = ''
        }, 500)
      }
    }

    const showEnlarge = ref(false)
    const currentEnlargeComponent = shallowRef()

    const onEnlargeClose = () => {
      showEnlarge.value = false
    }

    const onCenterTopEnlarge = () => {
      currentEnlargeComponent.value = centerTopModal
      showEnlarge.value = true
    }

    const onRightTopEnlarge = () => {
      currentEnlargeComponent.value = rightTopModal
      showEnlarge.value = true
    }

    return {
      handListChange,
      handPieChange,
      handIconClick,
      classId,
      goodsName,
      goodsId,
      refLeftTop,
      refLeftLower,
      refCenterTop,
      refCenterLower,
      refRightTop,
      refRightLower,
      refEnlarge,
      isTransition,
      transitionName,
      iconText,
      showEnlarge,
      currentEnlargeComponent,
      onEnlargeClose,
      onCenterTopEnlarge,
      onRightTopEnlarge
    }
  }
})
</script>
<style lang="less" scoped>
.P2 {
  display: flex;
  box-sizing: border-box;
  color: #fff;
  .item-icon {
    cursor: pointer;
    z-index: 2;
    font-size: 25px;
    margin-top: 12px;
    margin-left: 78px;
    &:hover {
      color: rgba(255, 255, 255, 0.5);
    }
    &.centerTop {
      margin-left: 138px;
    }
  }
  .left {
    box-sizing: border-box;
    overflow: hidden;
    flex: 1;
    margin-right: 7px;
  }
  .center {
    box-sizing: border-box;
    flex: 0 0 610px;
    margin: 0px 7px;
  }
  .right {
    overflow: hidden;
    box-sizing: border-box;
    flex: 0 0 610px;
    margin-left: 7px;
  }
}
.box {
  display: flex;
  flex-direction: column;
  .left-top {
    flex: 0 0 370px;
  }
  .left-lower {
    flex: 1;
  }
  .center-top {
    height: 50%;
    position: relative;
  }
  .center-lower {
    height: 50%;
  }
  .right {
    display: flex;
    flex-direction: column;

    .right-top {
      flex: 1;
    }
    .right-lower {
      flex: 1;
    }
  }
  .box-top {
    height: 100%;
    margin-bottom: 7px;
    flex: 1;
  }
  .box-lower {
    flex: 1;
    height: 100%;
    margin-top: 7px;
  }
  .enlarge-nav {
    float: left;
  }
  //进入过度
  .fade-enter-active,
  .fade-leave-active {
    transition: all 0.3s;
  }
  //·进入完成
  .fade-enter-to,
  .fade-leave-from {
    transform: translate3d(0px, 0px, 0px) scale(1);
  }

  // 中间顶部
  .centerTop-transition {
    transform: translate3d(0, -234px, 0) scale(0.7);
  }
}
</style>
